<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            msg: 'hello'
        }
        const abc = {
            demo: 'hhh'
        }
        function fn(x, y) {
            console.log(this)
            return x + y
        }
        // fn(1, 2)
        // fn.apply(this指向谁，[数组])
        const res = fn.apply(obj, [1, 2])
        console.log(res)

        // fn.apply()
        // 1. 改变this的指向
        // 2. 调用函数，立即执行
        // 3. 返回值就是函数本身的返回值

        // 注意：apply的第二个参数是数组
    </script>
</body>

</html>